<html>
<head><meta charset="utf-8"><title>How can I make this diagnostic better (if it can/should be)? · t-compiler/wg-diagnostics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/index.html">t-compiler/wg-diagnostics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html">How can I make this diagnostic better (if it can/should be)?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216820944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216820944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216820944">(Nov 15 2020 at 23:36)</a>:</h4>
<p>Hey there! I started to work on <a href="https://github.com/rust-lang/rust/issues/78941">#78491</a>, which basically makes a diagnostic more readable by changing the suggestion to be verbose. However, I feel that the following result isn't quite desirable:</p>
<div class="codehilite"><pre><span></span><code>error: functions in `extern` blocks cannot have qualifiers
 --&gt; &lt;anon&gt;:2:11
  |
1 | extern &quot;C&quot; {
  | ---------- in this `extern` block
2 |     async fn calleth();
  |              ^^^^^^^
  |
help: remove the qualifiers
  |
2 |     fn calleth();
  |     ^^

error: aborting due to previous error
</code></pre></div>
<p>Does anyone here have any suggestions on how to improve this (if needed)?</p>
<p>(p.s. I hope this is the right stream for this, if not, I can continue discussion in t-compiler)</p>



<a name="216821055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216821055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216821055">(Nov 15 2020 at 23:39)</a>:</h4>
<p>Note that the previous diagnostic was this:</p>
<div class="codehilite"><pre><span></span><code>error: functions in `extern` blocks cannot have qualifiers
 --&gt; src/lib.rs:2:14
  |
1 | extern &quot;C&quot; {
  | ---------- in this `extern` block
2 |     async fn calleth();
  |     ---------^^^^^^^
  |     |
  |     help: remove the qualifiers: `fn`

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.
</code></pre></div>



<a name="216821347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216821347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216821347">(Nov 15 2020 at 23:48)</a>:</h4>
<p>To me, the new diagnostic implies that you should remove the <code>fn</code> rather than implying that the snippet is what it should be. Perhaps I could change the diagnostic to not be verbose but have the message be something like "remove the qualifiers: <code>async</code>", if that's possible? I'm new to rustc contribution so I'm not quite sure if/how this should be improved.</p>



<a name="216827868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216827868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216827868">(Nov 16 2020 at 02:44)</a>:</h4>
<p>I liked it before :/</p>



<a name="216827875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216827875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216827875">(Nov 16 2020 at 02:45)</a>:</h4>
<p>although it would be more clear to say <code>fn calleth()</code> I think</p>



<a name="216827932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216827932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216827932">(Nov 16 2020 at 02:46)</a>:</h4>
<p>What part of the diagnostic be changed to say <code>fn calleth()</code>?</p>



<a name="216827952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216827952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216827952">(Nov 16 2020 at 02:47)</a>:</h4>
<p>the one that says just <code>fn</code> currently</p>



<a name="216827955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216827955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216827955">(Nov 16 2020 at 02:47)</a>:</h4>
<p>it makes it seem like you should remove <em>both</em> <code>async</code> and the name</p>



<a name="216829259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216829259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216829259">(Nov 16 2020 at 03:17)</a>:</h4>
<p>So you mean like this? (or the other new diagnostic?)</p>
<div class="codehilite"><pre><span></span><code>error: functions in `extern` blocks cannot have qualifiers
 --&gt; src/lib.rs:2:14
  |
1 | extern &quot;C&quot; {
  | ---------- in this `extern` block
2 |     async fn calleth();
  |     ---------^^^^^^^
  |     |
  |     help: remove the qualifiers: `fn calleth();`

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.
</code></pre></div>



<a name="216829344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216829344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216829344">(Nov 16 2020 at 03:19)</a>:</h4>
<p>yeah, that's what I was imagining</p>



<a name="216829643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216829643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216829643">(Nov 16 2020 at 03:26)</a>:</h4>
<p>Ok. How would I implement that? I know where the diagnostic is located (rustc_ast_passes) but I'm not sure how I'd get that to work.</p>



<a name="216829665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216829665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216829665">(Nov 16 2020 at 03:27)</a>:</h4>
<p>Actually, I'll just mess around and see if I can get it to work first. If that doesn't work, I'll seek further help.</p>



<a name="216831654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216831654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216831654">(Nov 16 2020 at 04:27)</a>:</h4>
<p>There's a better way to do this, right? I just want to get the code at that span. I know the span is valid because it's the beginning of one valid span to the end of another valid span.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">"fn {}"</span><span class="p">,</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">session</span><span class="p">.</span><span class="n">source_map</span><span class="p">().</span><span class="n">span_to_snippet</span><span class="p">(</span><span class="n">ident</span><span class="p">.</span><span class="n">span</span><span class="p">.</span><span class="n">to</span><span class="p">(</span><span class="n">span</span><span class="p">.</span><span class="n">shrink_to_hi</span><span class="p">())).</span><span class="n">unwrap</span><span class="p">())</span><span class="w"></span>
</code></pre></div>
<p>It works, but I just feel like I have ruined something sacred with my unclean, un-fully-researched-and-vetted code</p>
<div class="codehilite"><pre><span></span><code>error: functions in `extern` blocks cannot have qualifiers
 --&gt; &lt;anon&gt;:2:11
  |
1 | extern &quot;C&quot; {
  | ---------- in this `extern` block
2 |     async fn calleth();
  |     ---------^^^^^^^
  |     |
  |     help: remove the qualifiers: `fn calleth();`

error: aborting due to previous error
</code></pre></div>



<a name="216831953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216831953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216831953">(Nov 16 2020 at 04:35)</a>:</h4>
<p>Or well, I guess that's kind of XY-problem-y. I need to find a way to get a <code>String</code> from the state I have in <code>rustc_ast_passes::ast_validation::AstValidator::check_foreign_fn_headerless</code> that goes from the beginning of <code>fn</code> up to and including the semicolon</p>



<a name="216960904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216960904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216960904">(Nov 17 2020 at 02:49)</a>:</h4>
<p>It looks like the reviewer decided that wasn't what was best, so I'm reverting back to the diagnostic that was first shown (which was what was suggested by the reviewer). <span aria-label="confused" class="emoji emoji-1f615" role="img" title="confused">:confused:</span></p>



<a name="216961006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216961006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216961006">(Nov 17 2020 at 02:51)</a>:</h4>
<p>oh actually it turned out mostly the same</p>



<a name="216961021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216961021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216961021">(Nov 17 2020 at 02:51)</a>:</h4>
<p>because you have span_suggestion_verbose it shows the original code:</p>
<div class="codehilite"><pre><span></span><code>help: remove the qualifiers
   |
LL |         fn fe4();
   |         ^^
</code></pre></div>



<a name="216961024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216961024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216961024">(Nov 17 2020 at 02:51)</a>:</h4>
<p>which looks fine to me</p>



<a name="216961356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/How%20can%20I%20make%20this%20diagnostic%20better%20%28if%20it%20can/should%20be%29%3F/near/216961356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/How.20can.20I.20make.20this.20diagnostic.20better.20(if.20it.20can.2Fshould.20be).3F.html#216961356">(Nov 17 2020 at 02:58)</a>:</h4>
<p>true</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>